//
// Created by macos on 2021/11/23.
//

#ifndef TIMER_H
#define TIMER_H
#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <signal.h>

#define AUTORESET 1
#define NORESET   0

#define TASK_START(name, arg) void* name(void *arg){
#define TASK_END return NULL;}

typedef void* (*timer_task_t)(void* arg);

struct task_item{

    timer_task_t task;
    int init_counter;
    int counter;
    pthread_t th;
    void *arg;
    void *ret;
    int flag;
    int autoreset;

    struct task_item *next;

};

void timer_set_ticker(int val);

void* timer_event_loop(void* arg);

void timer_add_task(timer_task_t task, int val, int autoreset, void *arg);

void timer_wait();

void timer_stop();

void timer_start();

#endif //TIMER_H
